package com.haixiaoke.saas.order.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.haixiaoke.saas.apartment.domain.HousingAllocation;
import com.haixiaoke.saas.apartment.domain.UnsubscribeRule;
import com.haixiaoke.saas.common.annotation.Excel;
import com.haixiaoke.saas.common.core.domain.BaseEntity;
import com.haixiaoke.saas.contract.domain.LesseeContract;
import com.haixiaoke.saas.house.domain.House;
import lombok.Data;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;


/**
 * 订单对象 biz_order
 *
 * @author qixi
 * @date 2024-03-04
 */
@Data
public class Order extends BaseEntity {
    private static final long serialVersionUID = 1L;


    /**
     * 订单类型：1长短租 2日租
     */
    public static final String ORDER_TYPE_LONG_LEASE = "1";
    public static final String ORDER_TYPE_SHORT_LEASE = "2";


    /**
     * 订单id
     */
    private String orderId;

    /**
     * 房屋id
     */
    @Excel(name = "房屋id")
    @NotNull(message = "房屋id不能为空")
    private String houseId;

    /**
     * 房屋id
     */
    @Excel(name = "换房前id")
    private String beforeHouseId;

    /**
     * 楼盘id
     */
    @Excel(name = "楼盘id")
    private String estateId;

    /**
     * 楼盘名称
     */
    @Excel(name = "楼盘名称")
    private String estateName;

    /**
     * 楼栋id
     */
    @Excel(name = "楼栋id")
    private String buildingId;

    /**
     * 楼栋名称
     */
    @Excel(name = "楼栋名称")
    private String buildingName;

    /**
     * 单元id
     */
    @Excel(name = "单元id")
    private String unitId;

    /**
     * 单元名称
     */
    @Excel(name = "单元名称")
    private String unitName;

    /**
     * 省份id
     */
    @Excel(name = "省份id")
    private String provinceId;

    /**
     * 省份名称
     */
    @Excel(name = "省份名称")
    private String provinceName;

    /**
     * 市id
     */
    @Excel(name = "市id")
    private String cityId;

    /**
     * 市名称
     */
    @Excel(name = "市名称")
    private String cityName;

    /**
     * 区id
     */
    @Excel(name = "区id")
    private String districtId;

    /**
     * 区名称
     */
    @Excel(name = "区名称")
    private String districtName;

    /**
     * 所属街道
     */
    @Excel(name = "所属街道")
    private String streetId;

    /**
     * 街道名称
     */
    @Excel(name = "街道名称")
    private String streetName;

    /**
     * 所属社区
     */
    @Excel(name = "所属社区")
    private String communityId;

    /**
     * 社区名称
     */
    @Excel(name = "社区名称")
    private String communityName;

    /**
     * 小区地址
     */
    @Excel(name = "小区地址")
    private String premisesAddress;

    /**
     * 详细地址（省市区）
     */
    @Excel(name = "详细地址")
    private String fullAddress;

    /**
     * 订单状态; 1:待入住,2:签约审核,3:订单作废,4:超时未签约,5:签约中,6:签约失败,7:已入住,8:退租审核,9:退租中,10:协商退租,11:到期退租,12:换房审核,13:转租审核,14:超时退租中,15,续租审核
     * 短租状态：101:待付款,102取消支付,103待入住,104退订中,105退订成功,106已入住,107退房中,108已完成,151续租-待支付,152续租-已支付,153续租-取消支付,154续租-已完成
     */
    @Excel(name = "订单状态", readConverterExp = "1=待入住,2=签约审核,3=订单作废,4=超时未签约,5=签约中,6=签约失败,7=已入住,8=退租审核,9=退租中,10=协商退租,11=到期退租,12=换房审核,13=转租审核,14=超时退租中,15=续租审核"
            , combo = {"待签约", "签约审核", "订单作废", "超时未签约", "签约中", "签约失败", "已签约", "退租审核", "退租中", "协商退租", "到期退租", "换房审核", "转租审核", "超时退租中", "续租审核"})
    private String orderState;

    /**
     * 所在tab: 短租:1:待签约,2签约中,3合约中,4已退租,5失效      长租:1.待入住;3.已入住;4.已退租;5.失效
     */
    @Excel(name = "所在tab", readConverterExp = "1=待签约,2=签约中,3=合约中,4=已退租,5=失效"
            , combo = {"待签约", "签约中", "合约中", "已退租", "失效"})
    private String orderTab;

    /**
     * 预订人
     */
    @Excel(name = "预订人")
    @NotNull(message = "预订人不能为空")
    private String reserveUser;

    /**
     * 预定人id
     */
    @Excel(name = "预定人id")
    private Long reserveUserId;

    /**
     * 预订人手机号
     */
    @Excel(name = "预订人手机号")
    @NotNull(message = "预订人手机号不能为空")
    @Pattern(regexp = "(?:0|86|\\+86)?1[3456789]\\d{9}", message = "手机号格式不正确")
    private String reserveUserPhone;

    /**
     * 租户id
     */
    @Excel(name = "租户id")
    private String tenantId;

    /**
     * 部门id
     */
    @Excel(name = "部门id")
    private Long deptId;

    /**
     * 入住时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Excel(name = "入住时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    @NotNull(message = "入住时间不能为空")
    private Date checkInTime;

    /**
     * 退房时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Excel(name = "退房时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    @NotNull(message = "退房时间不能为空")
    private Date checkOutTime;

    /**
     * 实际入住时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Excel(name = "实际入住时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date realityCheckInTime;

    /**
     * 实际退房时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Excel(name = "实际退房时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date realityCheckOutTime;

    /**
     * 最晚签约时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Excel(name = "最晚签约时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date finallySignTime;

    /**
     * 已付租金
     */
    @Excel(name = "已付租金")
    private BigDecimal rentPaidNumber;

    /**
     * 已付押金
     */
    @Excel(name = "已付押金")
    private BigDecimal depositPaidNumber;

    /**
     * 订单来源：1订单管理;2嗨小克小程序;3.合同管理
     */
    @Excel(name = "订单来源", readConverterExp = "订单来源：1订单管理;2嗨小克小程序;3.合同管理", combo = {"订单管理", "嗨小克小程序"})
    private String orderSource;

    /**
     * 订单类型：1长短租 2日租
     */
    @Excel(name = "订单类型", readConverterExp = "1=长短租,2=日租", combo = {"长短租", "日租"})
    private String orderType;

    /**
     * 成交方式：1新签 2换房 3续租 4转租
     */
    @Excel(name = "成交方式", readConverterExp = "1=新签,2=换房,3=续租,4=转租", combo = {"新签", "换房", "续租", "转租"})
    private String tradingMode;


    /**
     * 关联订单
     */
    @Excel(name = "关联订单")
    private String linkedOrderId;

    /**
     * 免租天数
     */
    @Excel(name = "免租天数")
    private Long freeRentNumber;

    /**
     * 付款方式 :1.月付;2.一次性
     */
    @Excel(name = "付款方式 :1.月付;2.一次性")
    private String rentalMode;


    /**
     * 押几
     */
    @Excel(name = "押几")
    private Long depositNumber;

    /**
     * 付几
     */
    @Excel(name = "付几")
    private Long payNumber;

    /**
     * 押金
     */
    @Excel(name = "押金")
    private BigDecimal deposit;

    /**
     * 月租金
     */
    @Excel(name = "月租金")
    private BigDecimal monthRent;

    /**
     * 总租金
     */
    @Excel(name = "总租金")
    private BigDecimal totalRent;

    /**
     * 退款金额
     */
    @Excel(name = "退款金额")
    private BigDecimal refundAmount;

    /**
     * 补缴金额
     */
    @Excel(name = "补缴金额")
    private BigDecimal supplementaryPayment;

    private Integer memberNumber;

    /**
     * 租客信息
     */
    private OrderLessee orderLessee;

    private Order order;
    private List<Order> orderList;

    /**
     * 显示状态(0.显示,1.隐藏)
     */
    @Excel(name = "显示状态", readConverterExp = "0=显示,1=隐藏", combo = {"显示", "隐藏"})
    private String showState;
    /**
     * 退租申请时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Excel(name = "退租申请时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date checkOutApplicationTime;

    /**
     * 付款时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "付款时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date payTime;

    /**
     * 收租日类型:1.每期提前;2.每期第一个月;3.每期提前一个月
     */
    @Excel(name = "收租日类型:1.每期提前;2.每期第一个月;3.每期提前一个月")
    private String rentDayType;

    /**
     * 收租日(天/号)
     */
    @Excel(name = "收租日(天/号)")
    private Integer rentCollectionDate;

    /**
     * 账单生成日期(天)
     */
    @Excel(name = "账单生成日期(天)")
    private Integer billGenerationDate;

    /**
     * 账单生成规则:1.合同月;2.自然月
     */
    @Excel(name = "账单生成规则:1.合同月;2.自然月")
    private String billGenerationType;

    private String lesseeType;
    /**
     * 承租人姓名
     */
    private String lesseeName;
    /**
     * 承租人电话
     */
    private String phone;

    /**
     * 自定义字段：订单总金额,押金+总租金,收费金额
     */
    private BigDecimal totalPrice;

    /**
     * 订单快照对象
     */
    private OrderSnapshoot orderSnapshoot;
    /**
     * 房屋
     */
    private House house;
    /**
     * 换房的新房信息
     */
    private House houseNew;
    /**
     * 房屋配置
     */
    private HousingAllocation housingAllocation;
    /**
     * 退订规则
     */
    private UnsubscribeRule unsubscribeRule;

    /**
     * 续租订单的付款时间集合
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private List<Date> payTimeList;
    /**
     * 续租开始时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date reletCheckInTime;
    /**
     * 续租结束时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date reletCheckOutTime;
    /**
     * 房屋配置里的联系方式
     */
    private String contactPhone;
    /**
     * 经度
     */
    private Double longitude;

    /**
     * 纬度
     */
    private Double latitude;

    /**
     * 订单审核记录
     */
    private OrderAuditRecord orderAuditRecord;

    /**
     * 订单状态变更记录
     */
    private OrderStateRecord orderStateRecord;

    /**
     * 退房订单id
     */
    private CheckOutOrder checkOutOrder;

    /**
     * 订单退款、补缴类型,1退款2补缴
     */
    private String isRefundFlag;

    /**
     * 入住天数
     */
    private Integer rentDay;

    /**
     * 0不收取，1收取
     */
    private String chargeType;

    /**
     * 打扫状态：1.待指派；2.已指派；3.已完成
     */
    private String sweepState;

    /**
     * 验房结果：1.正常；2损坏
     */
    private String inspectionResult;

    /**
     * 验房id
     */
    private String[] houseInspectionIds;

    private List<OrderChargeItem> orderChargeItemList;
    private List<OrderHousingExpenses> orderHousingExpensesList;
    private List<OrderRefundItem> orderRefundItemList;
    private List<OrderRefundDetails> orderRefundDetailsList;
    private OrderHouseInspection orderHouseInspection;
    private List<Long> refundDetailsIds;

    /**
     * 续租金额
     */
    private BigDecimal reletPrice;

    /**
     * 已住金额
     */
    private BigDecimal checkInPrice;

    /**
     * 退订费
     */
    private BigDecimal unsubscribePrice;

    private OrderPriceVO orderPriceVO;

    private List<String> houseIds;

    /**
     * 是否有续租订单:0否1是
     */
    private String checkLinkedOrder;


    /**
     * 换房日期
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date changeDate;

    /**
     * 新增合同标识:0.可以新增合同;1.不可新增合同
     */
    private String newContractFlag;

    /**
     * 合同是否签署完成标识:0.没完成;1.已完成
     */
    private String contractSignFlag;

    /**
     * 租客合同
     */
    private LesseeContract lesseeContract;

    /**
     * 合作方式:1.房屋委托;2.代理服务
     */
    private String cooperationType;

}
